home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / mozilla-firefox / include / xpcom / nsStreamUtils.h < prev    next >
C/C++ Source or Header  |  2006-05-08  |  6KB  |  144 lines

  1. /* ***** BEGIN LICENSE BLOCK *****
  2.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  3.  *
  4.  * The contents of this file are subject to the Mozilla Public License Version
  5.  * 1.1 (the "License"); you may not use this file except in compliance with
  6.  * the License. You may obtain a copy of the License at
  7.  * http://www.mozilla.org/MPL/
  8.  *
  9.  * Software distributed under the License is distributed on an "AS IS" basis,
  10.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11.  * for the specific language governing rights and limitations under the
  12.  * License.
  13.  *
  14.  * The Original Code is Mozilla.
  15.  *
  16.  * The Initial Developer of the Original Code is
  17.  * Netscape Communications Corporation.
  18.  * Portions created by the Initial Developer are Copyright (C) 2002
  19.  * the Initial Developer. All Rights Reserved.
  20.  *
  21.  * Contributor(s):
  22.  *   Darin Fisher <darin@netscape.com>
  23.  *
  24.  * Alternatively, the contents of this file may be used under the terms of
  25.  * either the GNU General Public License Version 2 or later (the "GPL"), or
  26.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  27.  * in which case the provisions of the GPL or the LGPL are applicable instead
  28.  * of those above. If you wish to allow use of your version of this file only
  29.  * under the terms of either the GPL or the LGPL, and not to allow others to
  30.  * use your version of this file under the terms of the MPL, indicate your
  31.  * decision by deleting the provisions above and replace them with the notice
  32.  * and other provisions required by the GPL or the LGPL. If you do not delete
  33.  * the provisions above, a recipient may use your version of this file under
  34.  * the terms of any one of the MPL, the GPL or the LGPL.
  35.  *
  36.  * ***** END LICENSE BLOCK ***** */
  37.  
  38. #ifndef nsStreamUtils_h__
  39. #define nsStreamUtils_h__
  40.  
  41. #include "nscore.h"
  42.  
  43. class nsIInputStream;
  44. class nsIOutputStream;
  45. class nsIInputStreamCallback;
  46. class nsIOutputStreamCallback;
  47. class nsIEventTarget;
  48.  
  49. /**
  50.  * A "one-shot" proxy of the OnInputStreamReady callback.  The resulting
  51.  * proxy object's OnInputStreamReady function may only be called once!  The
  52.  * proxy object ensures that the real notify object will be free'd on the
  53.  * thread corresponding to the given event target regardless of what thread
  54.  * the proxy object is destroyed on.
  55.  *
  56.  * This function is designed to be used to implement AsyncWait when the
  57.  * aEventTarget parameter is non-null.
  58.  */
  59. extern NS_COM nsresult
  60. NS_NewInputStreamReadyEvent(nsIInputStreamCallback **aEvent,
  61.                             nsIInputStreamCallback  *aNotify,
  62.                             nsIEventTarget          *aEventTarget);
  63.  
  64. /**
  65.  * A "one-shot" proxy of the OnOutputStreamReady callback.  The resulting
  66.  * proxy object's OnOutputStreamReady function may only be called once!  The
  67.  * proxy object ensures that the real notify object will be free'd on the
  68.  * thread corresponding to the given event target regardless of what thread 
  69.  * the proxy object is destroyed on.
  70.  *
  71.  * This function is designed to be used to implement AsyncWait when the
  72.  * aEventTarget parameter is non-null.
  73.  */
  74. extern NS_COM nsresult
  75. NS_NewOutputStreamReadyEvent(nsIOutputStreamCallback **aEvent,
  76.                              nsIOutputStreamCallback  *aNotify,
  77.                              nsIEventTarget           *aEventTarget);
  78.  
  79. /* ------------------------------------------------------------------------- */
  80.  
  81. enum nsAsyncCopyMode {
  82.     NS_ASYNCCOPY_VIA_READSEGMENTS,
  83.     NS_ASYNCCOPY_VIA_WRITESEGMENTS
  84. };
  85.  
  86. /**
  87.  * This function is called when the async copy process completes.  The reported
  88.  * status is NS_OK on success and some error code on failure.
  89.  */
  90. typedef void (* nsAsyncCopyCallbackFun)(void *closure, nsresult status);
  91.  
  92. /**
  93.  * This function asynchronously copies data from the source to the sink. All
  94.  * data transfer occurs on the thread corresponding to the given event target.
  95.  * A null event target is not permitted.
  96.  *
  97.  * The copier handles blocking or non-blocking streams transparently.  If a
  98.  * stream operation returns NS_BASE_STREAM_WOULD_BLOCK, then the stream will
  99.  * be QI'd to nsIAsync{In,Out}putStream and its AsyncWait method will be used
  100.  * to determine when to resume copying.
  101.  */
  102. extern NS_COM nsresult
  103. NS_AsyncCopy(nsIInputStream         *aSource,
  104.              nsIOutputStream        *aSink,
  105.              nsIEventTarget         *aEventTarget,
  106.              nsAsyncCopyMode         aMode = NS_ASYNCCOPY_VIA_READSEGMENTS,
  107.              PRUint32                aChunkSize = 4096,
  108.              nsAsyncCopyCallbackFun  aCallbackFun = nsnull,
  109.              void                   *aCallbackClosure = nsnull);
  110.  
  111. /**
  112.  * This function tests whether or not the input stream is buffered.  A buffered
  113.  * input stream is one that implements readSegments.  The test for this is to
  114.  * simply call readSegments, without actually consuming any data from the
  115.  * stream, to verify that it functions.
  116.  *
  117.  * NOTE: If the stream is non-blocking and has no data available yet, then this
  118.  * test will fail.  In that case, we return false even though the test is not 
  119.  * really conclusive.
  120.  *
  121.  * @param aInputStream
  122.  *        The input stream to test.
  123.  */
  124. extern NS_COM PRBool
  125. NS_InputStreamIsBuffered(nsIInputStream *aInputStream);
  126.  
  127. /**
  128.  * This function tests whether or not the output stream is buffered.  A
  129.  * buffered output stream is one that implements writeSegments.  The test for
  130.  * this is to simply call writeSegments, without actually writing any data into
  131.  * the stream, to verify that it functions.
  132.  *
  133.  * NOTE: If the stream is non-blocking and has no available space yet, then
  134.  * this test will fail.  In that case, we return false even though the test is
  135.  * not really conclusive.
  136.  *
  137.  * @param aOutputStream
  138.  *        The output stream to test.
  139.  */
  140. extern NS_COM PRBool
  141. NS_OutputStreamIsBuffered(nsIOutputStream *aOutputStream);
  142.  
  143. #endif // !nsStreamUtils_h__
  144.